#coding:utf-8
import codecs
from  selenium import webdriver
driver = webdriver.PhantomJS()
driver.get("http://www.80s.tw/ju/list")
movies=driver.find_elements_by_xpath('//*[@id="block3"]/div[3]/ul[2]/li[9]')
cur_window =driver.current_window_handle
f =codecs.open("movies.doc",'w',encoding='utf-8')
for movie in movies:
    try:
        f.write( movie.text)
        f.write(',')
        movie.click()
        total_tab=driver.window_handles
        driver.switch_to_window(window_name=total_tab)
        thunder_link =driver.find_elements_by_xpath('//*[@id="block3"]/div[3]/ul[2]/li[9]/span[@class=xunlei dlbutton1]/a')
        f.write(thunder_link.__getattribute__("href"))
        driver.close()
        driver.switch_to_window(window_name=cur_window)
        print thunder_link.get_attribute("href")
    except Exception,e:







driver.quit()
